package com.bree.erp.entity;

import java.util.Collection;

import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.OneToMany;

@Entity
public class User implements CrudId<String> {

	@Id
	private String email;
	private String password;
	private String firstName;
	private String lastName;
	
	@OneToMany(mappedBy="user")
	private Collection<Group> groups;
	
	@Embedded
	private Audit audit;
	
	public String getDisplayName() {
		return firstName + " " + lastName;
	}

	@Override
	public String getId() {
		return email;
	}
	
	
	@Override
	public boolean equals(Object obj) {
		
		if(obj instanceof User && this.email != null) {
			User that = (User) obj;
			if(this.email.equals(that.email)) {
				return true;
			}
		}
		
		return false;
	}
	
	@Override
	public int hashCode() {
		return this.email == null ? 0 : this.email.hashCode();
	}

	/**
	 * @return the firstName
	 */
	public String getFirstName() {
		return firstName;
	}

	/**
	 * @param firstName the firstName to set
	 */
	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	/**
	 * @return the lastName
	 */
	public String getLastName() {
		return lastName;
	}

	/**
	 * @param lastName the lastName to set
	 */
	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	/**
	 * @return the audit
	 */
	public Audit getAudit() {
		return audit;
	}

	/**
	 * @param audit the audit to set
	 */
	public void setAudit(Audit audit) {
		this.audit = audit;
	}

	/**
	 * @return the email
	 */
	public String getEmail() {
		return email;
	}

	/**
	 * @param email the email to set
	 */
	public void setEmail(String email) {
		this.email = email;
	}

	/**
	 * @return the password
	 */
	public String getPassword() {
		return password;
	}

	/**
	 * @param password the password to set
	 */
	public void setPassword(String password) {
		this.password = password;
	}

	/**
	 * @return the groups
	 */
	public Collection<Group> getGroups() {
		return groups;
	}

	/**
	 * @param groups the groups to set
	 */
	public void setGroups(Collection<Group> groups) {
		this.groups = groups;
	}
	
	
}
